home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / calc202a.lha / calc-2.02a / calc-yank.el < prev    next >
Lisp/Scheme  |  1993-06-01  |  18KB  |  591 lines

  1. ;; Calculator for GNU Emacs, part II [calc-yank.el]
  2. ;; Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  3. ;; Written by Dave Gillespie, daveg@synaptics.com.
  4.  
  5. ;; This file is part of GNU Emacs.
  6.  
  7. ;; GNU Emacs is distributed in the hope that it will be useful,
  8. ;; but WITHOUT ANY WARRANTY.  No author or distributor
  9. ;; accepts responsibility to anyone for the consequences of using it
  10. ;; or for whether it serves any particular purpose or works at all,
  11. ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  12. ;; License for full details.
  13.  
  14. ;; Everyone is granted permission to copy, modify and redistribute
  15. ;; GNU Emacs, but only under the conditions described in the
  16. ;; GNU Emacs General Public License.   A copy of this license is
  17. ;; supposed to have been given to you along with GNU Emacs so you
  18. ;; can know your rights and responsibilities.  It should be in a
  19. ;; file named COPYING.  Among other things, the copyright notice
  20. ;; and this notice must be preserved on all copies.
  21.  
  22.  
  23.  
  24. ;; This file is autoloaded from calc-ext.el.
  25. (require 'calc-ext)
  26.  
  27. (require 'calc-macs)
  28.  
  29. (defun calc-Need-calc-yank () nil)
  30.  
  31.  
  32. ;;; Kill ring commands.
  33.  
  34. (defun calc-kill (nn &optional no-delete)
  35.   (interactive "P")
  36.   (if (eq major-mode 'calc-mode)
  37.       (calc-wrapper
  38.        (calc-force-refresh)
  39.        (calc-set-command-flag 'no-align)
  40.        (let ((num (max (calc-locate-cursor-element (point)) 1))
  41.          (n (prefix-numeric-value nn)))
  42.      (if (< n 0)
  43.          (progn
  44.            (if (eobp)
  45.            (setq num (1- num)))
  46.            (setq num (- num n)
  47.              n (- n))))
  48.      (let ((stuff (calc-top-list n (- num n -1))))
  49.        (calc-cursor-stack-index num)
  50.        (let ((first (point)))
  51.          (calc-cursor-stack-index (- num n))
  52.          (if (null nn)
  53.          (backward-char 1))   ; don't include newline for raw C-k
  54.          (copy-region-as-kill first (point))
  55.          (if (not no-delete)
  56.          (calc-pop-stack n (- num n -1))))
  57.        (setq calc-last-kill (cons (car kill-ring) stuff)))))
  58.     (kill-line nn))
  59. )
  60.  
  61. (defun calc-force-refresh ()
  62.   (if (or calc-executing-macro calc-display-dirty)
  63.       (let ((calc-executing-macro nil))
  64.     (calc-refresh)))
  65. )
  66.  
  67. (defun calc-locate-cursor-element (pt)
  68.   (save-excursion
  69.     (goto-char (point-max))
  70.     (calc-locate-cursor-scan (- calc-stack-top) calc-stack pt))
  71. )
  72.  
  73. (defun calc-locate-cursor-scan (n stack pt)
  74.   (if (or (<= (point) pt)
  75.       (null stack))
  76.       n
  77.     (forward-line (- (nth 1 (car stack))))
  78.     (calc-locate-cursor-scan (1+ n) (cdr stack) pt))
  79. )
  80.  
  81. (defun calc-kill-region (top bot &optional no-delete)
  82.   (interactive "r")
  83.   (if (eq major-mode 'calc-mode)
  84.       (calc-wrapper
  85.        (calc-force-refresh)
  86.        (calc-set-command-flag 'no-align)
  87.        (let* ((top-num (calc-locate-cursor-element top))
  88.           (bot-num (calc-locate-cursor-element (1- bot)))
  89.           (num (- top-num bot-num -1)))
  90.      (copy-region-as-kill top bot)
  91.      (setq calc-last-kill (cons (car kill-ring)
  92.                     (calc-top-list num bot-num)))
  93.      (if (not no-delete)
  94.          (calc-pop-stack num bot-num))))
  95.     (if no-delete
  96.     (copy-region-as-kill top bot)
  97.       (kill-region top bot)))
  98. )
  99.  
  100. (defun calc-copy-as-kill (n)
  101.   (interactive "P")
  102.   (calc-kill n t)
  103. )
  104.  
  105. (defun calc-copy-region-as-kill (top bot)
  106.   (interactive "r")
  107.   (calc-kill-region top bot t)
  108. )
  109.  
  110. ;;; This function uses calc-last-kill if possible to get an exact result,
  111. ;;; otherwise it just parses the yanked string.
  112. (defun calc-yank ()
  113.   (interactive)
  114.   (calc-wrapper
  115.    (calc-pop-push-record-list
  116.     0 "yank"
  117.     (if (eq (car-safe calc-last-kill) (car kill-ring-yank-pointer))
  118.     (cdr calc-last-kill)
  119.       (if (stringp (car kill-ring-yank-pointer))
  120.       (let ((val (math-read-exprs
  121.               (calc-clean-newlines (car kill-ring-yank-pointer)))))
  122.         (if (eq (car-safe val) 'error)
  123.         (progn
  124.           (setq val (math-read-exprs (car kill-ring-yank-pointer)))
  125.           (if (eq (car-safe val) 'error)
  126.               (error "Bad format in yanked data")
  127.             val))
  128.           val))))))
  129. )
  130.  
  131. (defun calc-clean-newlines (s)
  132.   (cond
  133.    
  134.    ;; Omit leading/trailing whitespace
  135.    ((or (string-match "\\`[ \n\r]+\\([^\001]*\\)\\'" s)
  136.     (string-match "\\`\\([^\001]*\\)[ \n\r]+\\'" s))
  137.     (calc-clean-newlines (math-match-substring s 1)))
  138.  
  139.    ;; Convert newlines to commas
  140.    ((string-match "\\`\\(.*\\)[\n\r]+\\([^\001]*\\)\\'" s)
  141.     (calc-clean-newlines (concat (math-match-substring s 1) ","
  142.                  (math-match-substring s 2))))
  143.    
  144.    (t s))
  145. )
  146.  
  147.  
  148. (defun calc-do-grab-region (top bot arg)
  149.   (and (memq major-mode '(calc-mode calc-trail-mode))
  150.        (error "This command works only in a regular text buffer."))
  151.   (let* ((from-buffer (current-buffer))
  152.      (calc-was-started (get-buffer-window "*Calculator*"))
  153.      (single nil)
  154.      data vals pos)
  155.     (if arg
  156.     (if (consp arg)
  157.         (setq single t)
  158.       (setq arg (prefix-numeric-value arg))
  159.       (if (= arg 0)
  160.           (save-excursion
  161.         (beginning-of-line)
  162.         (setq top (point))
  163.         (end-of-line)
  164.         (setq bot (point)))
  165.         (save-excursion
  166.           (setq top (point))
  167.           (forward-line arg)
  168.           (if (> arg 0)
  169.           (setq bot (point))
  170.         (setq bot top
  171.               top (point)))))))
  172.     (setq data (buffer-substring top bot))
  173.     (calc)
  174.     (if single
  175.     (setq vals (math-read-expr data))
  176.       (setq vals (math-read-expr (concat "[" data "]")))
  177.       (and (eq (car-safe vals) 'vec)
  178.        (= (length vals) 2)
  179.        (eq (car-safe (nth 1 vals)) 'vec)
  180.        (setq vals (nth 1 vals))))
  181.     (if (eq (car-safe vals) 'error)
  182.     (progn
  183.       (if calc-was-started
  184.           (pop-to-buffer from-buffer)
  185.         (calc-quit t)
  186.         (switch-to-buffer from-buffer))
  187.       (goto-char top)
  188.       (forward-char (+ (nth 1 vals) (if single 0 1)))
  189.       (error (nth 2 vals))))
  190.     (calc-slow-wrapper
  191.      (calc-enter-result 0 "grab" vals)))
  192. )
  193.  
  194.  
  195. (defun calc-do-grab-rectangle (top bot arg &optional reduce)
  196.   (and (memq major-mode '(calc-mode calc-trail-mode))
  197.        (error "This command works only in a regular text buffer."))
  198.   (let* ((col1 (save-excursion (goto-char top) (current-column)))
  199.      (col2 (save-excursion (goto-char bot) (current-column)))
  200.      (from-buffer (current-buffer))
  201.      (calc-was-started (get-buffer-window "*Calculator*"))
  202.      data mat vals lnum pt pos)
  203.     (if (= col1 col2)
  204.     (save-excursion
  205.       (or (= col1 0)
  206.           (error "Point and mark must be at beginning of line, or define a rectangle"))
  207.       (goto-char top)
  208.       (while (< (point) bot)
  209.         (setq pt (point))
  210.         (forward-line 1)
  211.         (setq data (cons (buffer-substring pt (1- (point))) data)))
  212.       (setq data (nreverse data)))
  213.       (setq data (extract-rectangle top bot)))
  214.     (calc)
  215.     (setq mat (list 'vec)
  216.       lnum 0)
  217.     (and arg
  218.      (setq arg (if (consp arg) 0 (prefix-numeric-value arg))))
  219.     (while data
  220.       (if (natnump arg)
  221.       (progn
  222.         (if (= arg 0)
  223.         (setq arg 1000000))
  224.         (setq pos 0
  225.           vals (list 'vec))
  226.         (let ((w (length (car data)))
  227.           j v)
  228.           (while (< pos w)
  229.         (setq j (+ pos arg)
  230.               v (if (>= j w)
  231.                 (math-read-expr (substring (car data) pos))
  232.               (math-read-expr (substring (car data) pos j))))
  233.         (if (eq (car-safe v) 'error)
  234.             (setq vals v w 0)
  235.           (setq vals (nconc vals (list v))
  236.             pos j)))))
  237.     (if (string-match "\\` *-?[0-9][0-9]?[0-9]?[0-9]?[0-9]?[0-9]? *\\'"
  238.               (car data))
  239.         (setq vals (list 'vec (string-to-int (car data))))
  240.       (if (and (null arg)
  241.            (string-match "[[{][^][{}]*[]}]" (car data)))
  242.           (setq pos (match-beginning 0)
  243.             vals (math-read-expr (math-match-substring (car data) 0)))
  244.         (let ((s (if (string-match
  245.               "\\`\\([0-9]+:[ \t]\\)?\\(.*[^, \t]\\)[, \t]*\\'"
  246.               (car data))
  247.              (math-match-substring (car data) 2)
  248.                (car data))))
  249.           (setq pos -1
  250.             vals (math-read-expr (concat "[" s "]")))
  251.           (if (eq (car-safe vals) 'error)
  252.           (let ((v2 (math-read-expr s)))
  253.             (or (eq (car-safe v2) 'error)
  254.             (setq vals (list 'vec v2)))))))))
  255.       (if (eq (car-safe vals) 'error)
  256.       (progn
  257.         (if calc-was-started
  258.         (pop-to-buffer from-buffer)
  259.           (calc-quit t)
  260.           (switch-to-buffer from-buffer))
  261.         (goto-char top)
  262.         (forward-line lnum)
  263.         (forward-char (+ (nth 1 vals) (min col1 col2) pos))
  264.         (error (nth 2 vals))))
  265.       (or (equal vals '(vec))
  266.       (setq mat (cons vals mat)))
  267.       (setq data (cdr data)
  268.         lnum (1+ lnum)))
  269.     (calc-slow-wrapper
  270.      (if reduce
  271.      (calc-enter-result 0 "grb+" (list reduce '(var add var-add)
  272.                        (nreverse mat)))
  273.        (calc-enter-result 0 "grab" (nreverse mat)))))
  274. )
  275.  
  276.  
  277. (defun calc-copy-to-buffer (nn)
  278.   "Copy the top of stack into an editing buffer."
  279.   (interactive "P")
  280.   (let ((thebuf (and (not (memq major-mode '(calc-mode calc-trail-mode)))
  281.              (current-buffer)))
  282.     (movept nil)
  283.     oldbuf newbuf)
  284.     (calc-wrapper
  285.      (save-excursion
  286.        (calc-force-refresh)
  287.        (let ((n (prefix-numeric-value nn))
  288.          (eat-lnums calc-line-numbering)
  289.          (big-offset (if (eq calc-language 'big) 1 0))
  290.          top bot)
  291.      (setq oldbuf (current-buffer)
  292.            newbuf (or thebuf
  293.               (calc-find-writable-buffer (buffer-list) 0)
  294.               (calc-find-writable-buffer (buffer-list) 1)
  295.               (error "No other buffer")))
  296.      (cond ((and (or (null nn)
  297.              (consp nn))
  298.              (= (calc-substack-height 0)
  299.             (- (1- (calc-substack-height 1)) big-offset)))
  300.         (calc-cursor-stack-index 1)
  301.         (if (looking-at
  302.              (if calc-line-numbering "[0-9]+: *[^ \n]" " *[^ \n]"))
  303.             (goto-char (1- (match-end 0))))
  304.         (setq eat-lnums nil
  305.               top (point))
  306.         (calc-cursor-stack-index 0)
  307.         (setq bot (- (1- (point)) big-offset)))
  308.            ((> n 0)
  309.         (calc-cursor-stack-index n)
  310.         (setq top (point))
  311.         (calc-cursor-stack-index 0)
  312.         (setq bot (- (point) big-offset)))
  313.            ((< n 0)
  314.         (calc-cursor-stack-index (- n))
  315.         (setq top (point))
  316.         (calc-cursor-stack-index (1- (- n)))
  317.         (setq bot (point)))
  318.            (t
  319.         (goto-char (point-min))
  320.         (forward-line 1)
  321.         (setq top (point))
  322.         (calc-cursor-stack-index 0)
  323.         (setq bot (point))))
  324.      (save-excursion
  325.        (set-buffer newbuf)
  326.        (if (consp nn)
  327.            (kill-region (region-beginning) (region-end)))
  328.        (push-mark (point) t)
  329.        (if (and overwrite-mode (not (consp nn)))
  330.            (calc-overwrite-string (save-excursion
  331.                     (set-buffer oldbuf)
  332.                     (buffer-substring top bot))
  333.                       eat-lnums)
  334.          (or (bolp) (setq eat-lnums nil))
  335.          (insert-buffer-substring oldbuf top bot)
  336.          (and eat-lnums
  337.           (let ((n 1))
  338.             (while (and (> (point) (mark))
  339.                 (progn
  340.                   (forward-line -1)
  341.                   (>= (point) (mark))))
  342.               (delete-char 4)
  343.               (setq n (1+ n)))
  344.             (forward-line n))))
  345.        (if thebuf (setq movept (point)))
  346.        (if (get-buffer-window (current-buffer))
  347.            (set-window-point (get-buffer-window (current-buffer))
  348.                  (point)))))))
  349.     (if movept (goto-char movept))
  350.     (and (consp nn)
  351.      (not thebuf)
  352.      (progn
  353.        (calc-quit t)
  354.        (switch-to-buffer newbuf))))
  355. )
  356.  
  357. (defun calc-overwrite-string (str eat-lnums)
  358.   (if (string-match "\n\\'" str)
  359.       (setq str (substring str 0 -1)))
  360.   (if eat-lnums
  361.       (setq str (substring str 4)))
  362.   (if (and (string-match "\\`[-+]?[0-9.]+\\(e-?[0-9]+\\)?\\'" str)
  363.        (looking-at "[-+]?[0-9.]+\\(e-?[0-9]+\\)?"))
  364.       (progn
  365.     (delete-region (point) (match-end 0))
  366.     (insert str))
  367.     (let ((i 0))
  368.       (while (< i (length str))
  369.     (if (= (setq last-command-char (aref str i)) ?\n)
  370.         (or (= i (1- (length str)))
  371.         (let ((pt (point)))
  372.           (end-of-line)
  373.           (delete-region pt (point))
  374.           (if (eobp)
  375.               (insert "\n")
  376.             (forward-char 1))
  377.           (if eat-lnums (setq i (+ i 4)))))
  378.       (self-insert-command 1))
  379.     (setq i (1+ i)))))
  380. )
  381.  
  382. ;;; First, require that buffer is visible and does not begin with "*"
  383. ;;; Second, require only that it not begin with "*Calc"
  384. (defun calc-find-writable-buffer (buf mode)
  385.   (and buf
  386.        (if (or (string-match "\\`\\( .*\\|\\*Calc.*\\)"
  387.                  (buffer-name (car buf)))
  388.            (and (= mode 0)
  389.             (or (string-match "\\`\\*.*" (buffer-name (car buf)))
  390.             (not (get-buffer-window (car buf))))))
  391.        (calc-find-writable-buffer (cdr buf) mode)
  392.      (car buf)))
  393. )
  394.  
  395.  
  396. (defun calc-edit (n)
  397.   (interactive "p")
  398.   (calc-slow-wrapper
  399.    (if (eq n 0)
  400.        (setq n (calc-stack-size)))
  401.    (let* ((flag nil)
  402.       (allow-ret (> n 1))
  403.       (list (math-showing-full-precision
  404.          (mapcar (if (> n 1)
  405.                  (function (lambda (x)
  406.                      (math-format-flat-expr x 0)))
  407.                (function
  408.                 (lambda (x)
  409.                   (if (math-vectorp x) (setq allow-ret t))
  410.                   (math-format-nice-expr x (screen-width)))))
  411.              (if (> n 0)
  412.                  (calc-top-list n)
  413.                (calc-top-list 1 (- n)))))))
  414.      (calc-edit-mode (list 'calc-finish-stack-edit (or flag n)) allow-ret)
  415.      (while list
  416.        (insert (car list) "\n")
  417.        (setq list (cdr list)))))
  418.   (calc-show-edit-buffer)
  419. )
  420.  
  421. (defun calc-alg-edit (str)
  422.   (calc-edit-mode '(calc-finish-stack-edit 0))
  423.   (calc-show-edit-buffer)
  424.   (insert str "\n")
  425.   (backward-char 1)
  426.   (calc-set-command-flag 'do-edit)
  427. )
  428.  
  429. (defvar calc-edit-mode-map nil "Keymap for use by the calc-edit command.")
  430. (if calc-edit-mode-map
  431.     ()
  432.   (setq calc-edit-mode-map (make-sparse-keymap))
  433.   (define-key calc-edit-mode-map "\n" 'calc-edit-finish)
  434.   (define-key calc-edit-mode-map "\r" 'calc-edit-return)
  435.   (define-key calc-edit-mode-map "\C-c\C-c" 'calc-edit-finish)
  436. )
  437.  
  438. (defun calc-edit-mode (&optional handler allow-ret title)
  439.   "Calculator editing mode.  Press RET, LFD, or C-c C-c to finish.
  440. To cancel the edit, simply kill the *Calc Edit* buffer."
  441.   (interactive)
  442.   (or handler
  443.       (error "This command can be used only indirectly through calc-edit."))
  444.   (let ((oldbuf (current-buffer))
  445.     (buf (get-buffer-create "*Calc Edit*")))
  446.     (set-buffer buf)
  447.     (kill-all-local-variables)
  448.     (use-local-map calc-edit-mode-map)
  449.     (setq buffer-read-only nil)
  450.     (setq truncate-lines nil)
  451.     (setq major-mode 'calc-edit-mode)
  452.     (setq mode-name "Calc Edit")
  453.     (run-hooks 'calc-edit-mode-hook)
  454.     (make-local-variable 'calc-original-buffer)
  455.     (setq calc-original-buffer oldbuf)
  456.     (make-local-variable 'calc-return-buffer)
  457.     (setq calc-return-buffer oldbuf)
  458.     (make-local-variable 'calc-one-window)
  459.     (setq calc-one-window (and (one-window-p t) pop-up-windows))
  460.     (make-local-variable 'calc-edit-handler)
  461.     (setq calc-edit-handler handler)
  462.     (make-local-variable 'calc-restore-trail)
  463.     (setq calc-restore-trail (get-buffer-window (calc-trail-buffer)))
  464.     (make-local-variable 'calc-allow-ret)
  465.     (setq calc-allow-ret allow-ret)
  466.     (erase-buffer)
  467.     (insert (or title title "Calc Edit Mode")
  468.         ".  Press "
  469.         (if (eq (lookup-key (current-global-map) "\e#") 'calc-dispatch)
  470.         "M-# M-# or C-c C-c"
  471.           (if allow-ret "C-c C-c" "RET"))
  472.         " to finish, "
  473.         (if (eq (lookup-key (current-global-map) "\e#") 'calc-dispatch)
  474.         "M-# x"
  475.           "C-x k RET")
  476.         " to cancel.\n"))
  477. )
  478. (put 'calc-edit-mode 'mode-class 'special)
  479.  
  480. (defun calc-show-edit-buffer ()
  481.   (let ((buf (current-buffer)))
  482.     (if (and (one-window-p t) pop-up-windows)
  483.     (pop-to-buffer (get-buffer-create "*Calc Edit*"))
  484.       (and calc-embedded-info (get-buffer-window (aref calc-embedded-info 1))
  485.        (select-window (get-buffer-window (aref calc-embedded-info 1))))
  486.       (switch-to-buffer (get-buffer-create "*Calc Edit*")))
  487.     (setq calc-return-buffer buf)
  488.     (if (and (< (window-width) (screen-width))
  489.          calc-display-trail)
  490.     (let ((win (get-buffer-window (calc-trail-buffer))))
  491.       (if win
  492.           (delete-window win))))
  493.     (set-buffer-modified-p nil)
  494.     (goto-char (point-min))
  495.     (forward-line 1))
  496. )
  497.  
  498. (defun calc-edit-return ()
  499.   (interactive)
  500.   (if (and (boundp 'calc-allow-ret) calc-allow-ret)
  501.       (newline)
  502.     (calc-edit-finish))
  503. )
  504.  
  505. (defun calc-edit-finish (&optional keep)
  506.   "Finish calc-edit mode.  Parse buffer contents and push them on the stack."
  507.   (interactive "P")
  508.   (message "Working...")
  509.   (or (and (boundp 'calc-original-buffer)
  510.        (boundp 'calc-return-buffer)
  511.        (boundp 'calc-one-window)
  512.        (boundp 'calc-edit-handler)
  513.        (boundp 'calc-restore-trail)
  514.        (eq major-mode 'calc-edit-mode))
  515.       (error "This command is valid only in buffers created by calc-edit."))
  516.   (let ((buf (current-buffer))
  517.     (original calc-original-buffer)
  518.     (return calc-return-buffer)
  519.     (one-window calc-one-window)
  520.     (disp-trail calc-restore-trail))
  521.     (save-excursion
  522.       (if (or (null (buffer-name original))
  523.           (progn
  524.         (set-buffer original)
  525.         (not (eq major-mode 'calc-mode))))
  526.       (error "Original calculator buffer has been corrupted.")))
  527.     (goto-char (point-min))
  528.     (if (looking-at "Calc Edit\\|Editing ")
  529.     (forward-line 1))
  530.     (if (buffer-modified-p)
  531.     (eval calc-edit-handler))
  532.     (if one-window
  533.     (delete-window))
  534.     (if (get-buffer-window return)
  535.     (select-window (get-buffer-window return))
  536.       (switch-to-buffer return))
  537.     (if keep
  538.     (bury-buffer buf)
  539.       (kill-buffer buf))
  540.     (if disp-trail
  541.     (calc-wrapper
  542.      (calc-trail-display 1 t)))
  543.     (message ""))
  544. )
  545.  
  546. (defun calc-edit-cancel ()
  547.   "Cancel calc-edit mode.  Ignore the Calc Edit buffer and don't change stack."
  548.   (interactive)
  549.   (let ((calc-edit-handler nil))
  550.     (calc-edit-finish))
  551.   (message "(Cancelled)")
  552. )
  553.  
  554. (defun calc-finish-stack-edit (num)
  555.   (let ((buf (current-buffer))
  556.     (str (buffer-substring (point) (point-max)))
  557.     (start (point))
  558.     pos)
  559.     (if (and (integerp num) (> num 1))
  560.     (while (setq pos (string-match "\n." str))
  561.       (aset str pos ?\,)))
  562.     (switch-to-buffer calc-original-buffer)
  563.     (let ((vals (let ((calc-language nil)
  564.               (math-expr-opers math-standard-opers))
  565.           (and (string-match "[^\n\t ]" str)
  566.                (math-read-exprs str)))))
  567.       (if (eq (car-safe vals) 'error)
  568.       (progn
  569.         (switch-to-buffer buf)
  570.         (goto-char (+ start (nth 1 vals)))
  571.         (error (nth 2 vals))))
  572.       (calc-wrapper
  573.        (if (symbolp num)
  574.        (progn
  575.          (set num (car vals))
  576.          (calc-refresh-evaltos num))
  577.      (if disp-trail
  578.          (calc-trail-display 1 t))
  579.      (and vals
  580.           (let ((calc-simplify-mode (if (eq last-command-char ?\C-j)
  581.                         'none
  582.                       calc-simplify-mode)))
  583.         (if (>= num 0)
  584.             (calc-enter-result num "edit" vals)
  585.           (calc-enter-result 1 "edit" vals (- num)))))))))
  586. )
  587.  
  588.  
  589.  
  590.  
  591.